package com.qipay.baas.mapper;

import com.qipay.baas.model.CpAccountTradlog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CpAccountTradlogMapper {
    @Delete({
        "delete from cp_account_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into cp_account_tradlog (cp_id, amount, ",
        "account_type, channel_type, ",
        "total, trade_no, remark, ",
        "create_time)",
        "values (#{cpId,jdbcType=BIGINT}, #{amount,jdbcType=INTEGER}, ",
        "#{accountType,jdbcType=TINYINT}, #{channelType,jdbcType=TINYINT}, ",
        "#{total,jdbcType=INTEGER}, #{tradeNo,jdbcType=CHAR}, #{remark,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(CpAccountTradlog record);

    @InsertProvider(type=CpAccountTradlogSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(CpAccountTradlog record);

    @Select({
        "select",
        "id, cp_id, amount, account_type, channel_type, total, trade_no, remark, create_time",
        "from cp_account_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT),
        @Result(column="amount", property="amount", jdbcType=JdbcType.INTEGER),
        @Result(column="account_type", property="accountType", jdbcType=JdbcType.TINYINT),
        @Result(column="channel_type", property="channelType", jdbcType=JdbcType.TINYINT),
        @Result(column="total", property="total", jdbcType=JdbcType.INTEGER),
        @Result(column="trade_no", property="tradeNo", jdbcType=JdbcType.CHAR),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    CpAccountTradlog selectByPrimaryKey(Long id);

    @UpdateProvider(type=CpAccountTradlogSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CpAccountTradlog record);

    @Update({
        "update cp_account_tradlog",
        "set cp_id = #{cpId,jdbcType=BIGINT},",
          "amount = #{amount,jdbcType=INTEGER},",
          "account_type = #{accountType,jdbcType=TINYINT},",
          "channel_type = #{channelType,jdbcType=TINYINT},",
          "total = #{total,jdbcType=INTEGER},",
          "trade_no = #{tradeNo,jdbcType=CHAR},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CpAccountTradlog record);
}